import moment from 'moment'

const getRandom = (start = 0, range = 100) => {
  return (start + Math.round(range * Math.random()))
}

export const makeScore = () => getRandom(60, 40)

export const makeRadarData = (members) => {
  const items = [
    { item: '评分' },
    { item: '目标总数占比' },
    { item: '目标完成率' },
    { item: '结果总数占比' },
    { item: '结果完成率' }
  ]

  items.forEach(item => {
    members.forEach(member => {
      item[member] = makeScore()
    })
  })

  return items
}

export const makeUserIcon = () => {
  const index = getRandom(1, 18)
  return './users/' + index + '.png'
}

export const mockViewedData = () => {
  const viewedData = []
  for (let i = 0; i < 14; i++) {
    viewedData.push({
      visitDate: moment().subtract(i, 'days').format('YYYYMMDD'),
      visitTimes: getRandom(10, 400)
    })
  }

  return viewedData
}

export const mockInstanceDistribution = ({ type }) => {
  let pieData = []
  if (type === 'sponsor') {
    pieData = [
      { count: 4, state: 'NEW', stateDesc: '创建中' },
      { count: 2, state: 'RECRUIT', stateDesc: '招募中' },
      { count: 5, state: 'IN_PROGRESS', stateDesc: '执行中' },
      { count: 3, state: 'DONE', stateDesc: '已完成' },
      { count: 1, state: 'ABANDONED', stateDesc: '已废弃' }
    ]
  } else {
    pieData = [
      { count: 1, state: 'NEW', stateDesc: '创建中' },
      { count: 3, state: 'RECRUIT', stateDesc: '招募中' },
      { count: 5, state: 'IN_PROGRESS', stateDesc: '执行中' },
      { count: 5, state: 'DONE', stateDesc: '已完成' },
      { count: 2, state: 'ABANDONED', stateDesc: '已废弃' }
    ]
  }
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(pieData)
    }, 2000)
  })
}
